﻿var Dept = Backbone.Model.extend({
    defaults: {
        'id': 0,
        'Name': '',
        'OfficeCode': '',
        'Description':'',
        'Node': 0,
        'ParentId': null,
        'ParentName': '',
        'IsActive': true,
        'SubDepts':[],
        'nocache': (new Date()).toJSON()
    },
    
    /* model có id bang 0 là model mới url sẽ là add */
    isNew: function () {
        var id = this.get('id');
        if (!id || id == 0) {
            return true;
        }
        return false;
    },
    /*
        lấy url
    */
    url: function () {
        if (this.isNew()) {
            return '/department/add_dept';
        } else {
            return '/department/update_dept';
        }
    }
});

var DeptCollection = Backbone.Collection.extend({
    model: Dept
});

// User In Department Model
var UID = Backbone.Model.extend({
    initialize: function () {
    },
    defaults: {
        UserName: VOfficeHelper.NewGuid(),
        DepartmentId: 0,
        IsInDept: false
    },
    url: '/department/assign_user'
});
// User In Role Collection
var UidCollection = Backbone.Collection.extend({
    model: UID
});